﻿using System;
using System.Messaging;

namespace Lite.Messaging.Msmq
{
    public class MsmqMessageFactory
        : IMessageFactory
    {
        private static Message CreateNewMessage()
        {
            Message message = new Message();
            message.Formatter = FormatterFactory.Formatter;

            return message;
        }

        internal static IReceiveMessage CreateMessage(Message message)
        {
            message.Formatter = FormatterFactory.Formatter;
            return new MsmqReceiveMessage(message);
        }

        #region IMessageFactory Members

        public ISendMessage CreateMessage()
        {
            Message message = CreateNewMessage();

            return new MsmqSendMessage(message);
        }

        public ISendMessage CreateMessage(object conversationId)
        {
            Message message = CreateNewMessage();
            message.CorrelationId = conversationId.ToString();
            return new MsmqSendMessage(message);
        }

        #endregion
    }
}
